//
//  WBBaseView.swift
//  XLWibo-Swift
//
//  Created by 王林 on 2016/11/13.
//  Copyright © 2016年 木木. All rights reserved.
//

import UIKit
import SnapKit

@objc protocol WBBaseViewDelegate:NSObjectProtocol {

   @objc optional func clickLoginDelegate()
    
    @objc optional func clickRegister()
    
    
}


class WBBaseView: UIView {
    
    //MARK:  -
    //MARK:  - 声明代理属性
   weak var deleagte : WBBaseViewDelegate?
    
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    
        self.backgroundColor = UIColor.init(white: 237.0 / 255.0, alpha: 1)
    }
    
    
    //MARK:  -
    //MARK:  - 重构访客视图
    func updataInfo(imageName:String,title:String,isHome:Bool = false){
        imgViewCricle.image = UIImage(named: imageName)
        lblText.text = title
        if isHome {
            animation()
        }
        else{
            imgViewHouse.isHidden = true
            imgViewHouse.isHidden = true
        }
    }
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    

   lazy var imgViewCricle = UIImageView(image: #imageLiteral(resourceName: "visitordiscover_feed_image_smallicon"))
    lazy var imgViewHouse = UIImageView(image: #imageLiteral(resourceName: "visitordiscover_feed_image_house"))
    lazy var converView = UIImageView(image: #imageLiteral(resourceName: "visitordiscover_feed_mask_smallicon"))
    
    lazy var lblText = UILabel.init(title: "今天是个好日子,好日子啊 好日子,两只小蜜蜂啊 ,飞到花丛中阿", titleColor: UIColor.darkGray, font: UIFont.systemFont(ofSize: 14))
    
    lazy var loginBtn = UIButton.init(titil: "登录", textColor: UIColor.darkGray, titleFont: UIFont.systemFont(ofSize: 13),target: self, action: #selector(clickLogin))
    
    
    lazy var registerBtn = UIButton.init(titil: "注册", textColor: UIColor.orange, titleFont: UIFont.systemFont(ofSize: 13),target: self, action: #selector(clickRegister))
    
    
   @objc private func clickLogin(){
    
    deleagte?.clickLoginDelegate?()
    }
   
   @objc private func clickRegister(){

    deleagte?.clickRegister?()
    }
    
    //MARK:  -
    //MARK:  - 圈圈转起来
    func animation(){
        let animation = CABasicAnimation(keyPath: "transform.rotation")
        animation.toValue = (M_PI * 2)
        animation.repeatCount = MAXFLOAT
        animation.duration = 15
        animation.isRemovedOnCompletion = false
      imgViewCricle.layer.add(animation, forKey: "123")
    }
    
    
    func setupUI(){
        addSubview(imgViewCricle)
        addSubview(converView)
        addSubview(imgViewHouse)
        addSubview(lblText)
        addSubview(loginBtn)
        addSubview(registerBtn)
        
        
        imgViewCricle.snp.makeConstraints { (make) in
            make.centerX.equalTo(self)
            make.centerY.equalTo(self).offset(-80)
        }
        converView.snp.makeConstraints { (make) in
            make.center.equalTo(imgViewCricle)
        }
        imgViewHouse.snp.makeConstraints { (make) in
            make.center.equalTo(imgViewCricle)
        }
        lblText.snp.makeConstraints { (make) in
            make.width.equalTo(220)
            make.top.equalTo(imgViewCricle.snp.bottom).offset(20)
            make.centerX.equalTo(imgViewHouse)
        }
        loginBtn.snp.makeConstraints { (make) in
            make.leading.equalTo(lblText.snp.leading)
            make.width.equalTo(100)
             make.top.equalTo(lblText.snp.bottom).offset(20)
        }
        registerBtn.snp.makeConstraints { (make) in
            make.trailing.equalTo(lblText.snp.trailing)
            make.top.equalTo(lblText.snp.bottom).offset(20)
            make.width.equalTo(100)
        }
      
        
    }
    

}







